from itertools import count, izip
from primes import totient_gen

limit = 10000000
#limit = 40

min = 100
minn = 0
tgen = totient_gen(limit)
tgen.next() # n should be > 1, so skip totient(1)

for (n, tn) in izip(count(2), tgen):
    ratio = n  * 1.0 / tn
    if ratio < min and sorted(str(n)) == sorted(str(tn)):
        min = ratio
        minn = n
        print "MIN: ", minn, min